#include "sampler1.h"

using namespace SPLINTER;

Sampler1::Sampler1(int factor) : factor(factor), m_derivation(factor) {}

DenseVector Sampler1::operator()(DenseVector x) const
{
    double x0 = x(0);
    DenseVector y(1);
    y(0) = 1. / (1. + factor * x0 * x0);
    return y;
}

const ISampler &Sampler1::derivation() const { return m_derivation; }

Sampler1::Derivation::Derivation(int factor) : factor(factor), m_derivation(factor) {}

DenseVector Sampler1::Derivation::operator()(DenseVector x) const
{
    double x0 = x(0);
    DenseVector y(1);
    y(0) = -2. * factor * x0 / pow(1. + factor * x0 * x0, 2);
    return y;
}

const ISampler &Sampler1::Derivation::derivation() const { return m_derivation; }

Sampler1::Derivation::Derivation2::Derivation2(int factor) : factor(factor) {}

DenseVector Sampler1::Derivation::Derivation2::operator()(DenseVector x) const
{
    double x0 = x(0);
    DenseVector y(1);
    y(0) = (-2. * factor + 6. * factor * factor * x0 * x0) / pow(1. + factor * x0 * x0, 3);
    return y;
}
